import { login } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
// import { resetRouter } from '@/router'

const state = {
  // 初始化：从cookie中去读取
  token: getToken()
}
const mutations = {
  // 设置token
  setToken(state, data) {
    state.date = data // 存state
    setToken(data) // 存cookie
  },
  // 删除token
  removeToken(state) {
    state.token = null
    removeToken()
  }
}
const actions = {
  async loginAction(context, data) {
    const res = await login(data)
    context.commit('setToken', res)
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}

